/**
 * @file        main.c
 * @brief       GPIO Example
 * @details
 */

/*******************************************************************************
 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of Maxim Integrated
 * Products, Inc. shall not be used except as stated in the Maxim Integrated
 * Products, Inc. Branding Policy.
 *
 * The mere transfer of this software does not imply any licenses
 * of trade secrets, proprietary technology, copyrights, patents,
 * trademarks, maskwork rights, or any other form of intellectual
 * property whatsoever. Maxim Integrated Products, Inc. retains all
 * ownership rights.
 *
 * $Date: 2018-08-09 18:45:02 -0500 (Thu, 09 Aug 2018) $
 * $Revision: 36818 $
 *
 ******************************************************************************/

/* **** Includes **** */
#include "include.h"
/* **** Definitions **** */

/* **** Globals **** */

int error, i = 0;
const sys_cfg_i2c_t sys_i2c_cfg = NULL; /* No system specific configuration needed. */

/* **** Functions **** */

/* Toggles GPIO when continuous timer repeats */
extern short ax,ay,az;
int main(void)
{
//    printf("\n\n***** GPIO Example ******\n\n");
//    printf("1. This example reads P0.12 (S1) and outputs the same state onto P0.13 (DS1).\n");
//    printf("2. An interrupt is set up on P0.3. P0.2 toggles when that interrupt occurs.\n\n");

		InitGraph();
//		OledPrintf("OLED_READY\n");
    //Setup the I2CM
    I2C_Shutdown(I2C_MASTER);
    if((error = I2C_Init(I2C_MASTER, I2C_STD_MODE, &sys_i2c_cfg)) != E_NO_ERROR) {
        OledPrintf("Error initializing I2C%d.  (Error code = %d)\n", I2C_MASTER_IDX, error);
        return 1;
    }
//    I2C_Init(I2C_MASTER, I2C_STD_MODE, &sys_i2c_cfg);
		
//		OledPrintf("MPU_init_ready\n");
		MPU_Init();
		
		IT_init();
		UART1A_init();
//		GPIO_INIT();
//		int i=0;
    while (1) {
//			get_uart();
//			OledPrintf("%x\n",UART_ReadByte(MXC_UART_GET_UART(1)));
//			MPU_Get_Accelerometer(&ax,&ay,&az);

//			OledPrintf("ax:%d\n",ax);
//			if(ax==0) OledPrintf("NULL\n");
//			else OledPrintf("ax:%d\n",ax);
//			OledPrintf("OLED_TEST\n");
//			GPIO_OutSet(&GPIO_CLK);
//			GPIO_OutSet(&GPIO_DIN);
//			mxc_delay(1000);
//			GPIO_OutClr(&GPIO_CLK);
//			GPIO_OutClr(&GPIO_DIN);
//			mxc_delay(100000);
    }
}
